package com.google.code.lightsomy.http;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

/**
 * Response buffer that holds JSP rendering output.
 * 
 * @author Viktoras Agejevas
 *
 */
public class HttpResponseBuffer extends HttpServletResponseWrapper {

	private PrintWriter writer = null;
	
	private ByteArrayOutputStream baos = null;

	public HttpResponseBuffer(HttpServletResponse response) {
		super(response);
		baos = new ByteArrayOutputStream();
		writer = new PrintWriter(baos);
	}

	public PrintWriter getWriter() throws IOException {
		return writer;
	}

	@Override
	public String toString() {
		writer.flush();
		writer.close();
		return baos.toString();
	}
}